/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pos.Driving.Dashboard.Image;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3f;
import pos.ControlCenter;
import pos.utils.Invokeable;
import pos.utils.ObjectFactory;

/**
 *
 * @author Administrator
 */
public class ControlPane3D extends BranchGroup implements Invokeable{
    private float fxStep;
    private double pow;
    private TransformGroup tgCPRoot;
    private TransformGroup tgHandle,tgHandleR;

    public ControlPane3D(Transform3D transform) {
        tgCPRoot= new TransformGroup(transform);
        //this.setTransform(transform);
        this.setCapability(ALLOW_DETACH);
        this.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
        initObjects();
        this.addChild(tgCPRoot);
        this.compile();
    }

    public void setPow(double pow) {
        this.pow = pow;
        double posY=0;
        if (pow>-1.01)     //break
            posY=-pow*Math.PI/4;
        Transform3D t3d = new Transform3D();
        t3d.rotX(posY);
        tgHandleR.setTransform(t3d);
    }

    @Override
    public void invoke(double Step) {
        fxStep=(fxStep+(float)Step) % 100f;
    }

    private void initObjects(){
        tgCPRoot.addChild(ObjectFactory.createObject(
                "Model.Train.AC01.DriveDesk", false));

        Transform3D t3d=new Transform3D();
        t3d.set(new Vector3f(1.05f, 1.904f,0.65f));
        tgHandle=new TransformGroup(t3d);
        tgHandleR = new TransformGroup();
        tgHandleR.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        tgHandleR.addChild(ObjectFactory.createObject(
                "Model.Train.AC01.PowerHandle", false));
        tgHandle.addChild(tgHandleR);
        tgCPRoot.addChild(tgHandle);

        /*t3d.set(new Vector3f(-3.22f,3.1f,0.01f));
        tgDoorTips=new TransformGroup(t3d);
        tgDoorTips.addChild(ObjectFactory.createTexturedSurface(0.6f, 0.6f, 0,
                new Color3f(1f,1f,1f), 0.1f,
                PathRes.getPath("Image.DriveRoom.DoorTips")));
        tgCPRoot.addChild(tgDoorTips);

        t3d.set(new Vector3f(-0.2f,-0.4f,0.01f));
        tgEB=new TransformGroup(t3d);
        planeEB=(Plane2D)ObjectFactory.createTexturedSurface(0.5f, 0.5f, 0,
                new Color3f(1f,1f,1f), 0,
                PathRes.getPath("Image.DriveRoom.EBButton"));
        tgEB.addChild(planeEB);
        tgCPRoot.addChild(tgEB);*/
    }
    //TempCode
    public void setVisualType(int type){
       // Transform3D t3d=new Transform3D();
        switch (type){
            case 3:
                if (!this.isLive()){
                     ControlCenter.dashBoardRoot.insertChild(this, 0);
                }
                break;

            default:    //Show nothing
                if (this.isLive())
                    this.detach();
                break;
        }
//tgCPRoot.setTransform(t3d);
    }
}
